home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / programr / toolbar / tbtest.c next >
C/C++ Source or Header  |  1991-07-28  |  5KB  |  137 lines

  1. #include <windows.h>
  2. #include "toolbar.h"
  3.  
  4. static HWND tbhwnd1, tbhwnd2, cbhwnd;
  5.  
  6. static TOOLBARICON tbar1[] = {
  7.     { 2, 200, 6, 24, 24, 1, 0, NULL, "Kana_Undep", "Kana_Dep", "Kana_Grayed", "Kana_Pressed" },
  8.     { 1, 230, 6, 24, 24, 0, 0, NULL, "Ascii_Undep", "Ascii_Dep", "Ascii_Grayed", "Ascii_Pressed" },
  9.     { 9, 270, 6, 24, 24, 0, 1, "CVT_Disabled", "CVT_Undep", NULL, NULL, "CVT_Pressed" },
  10.     { 3, 310, 6, 24, 24, -1, 3, "Bold_Disabled", "Bold_Undep", "Bold_Dep", "Bold_Grayed", "Bold_Pressed" },
  11.     { 4, 340, 6, 24, 24, -1, 3, "Italics_Disabled", "Italics_Undep", "Italics_Dep", "Italics_Grayed", "Italics_Pressed" },
  12.     { 5, 370, 6, 24, 24, 0, 3, "Und_Disabled", "Und_Undep", "Und_Dep", "Und_Grayed", "Und_Pressed" },
  13.     { 6, 400, 6, 24, 24, 0, 3, "Rev_Disabled", "Rev_Undep", "Rev_Dep", "Rev_Grayed", "Rev_Pressed" }
  14. };
  15. static TOOLBARICON tbar2[] = {
  16.     { 7, 200, 6, 24, 24, 1, 0, "LR_Disabled", "LR_Undep", "LR_Dep", "LR_Grayed", "LR_Pressed" },
  17.     { 8, 230, 6, 24, 24, 0, 0, "UD_Disabled", "UD_Undep", "UD_Dep", "UD_Grayed", "UD_Pressed" }
  18. };
  19.  
  20. long FAR PASCAL MainWinProc (HWND, WORD, WORD, LONG);
  21.  
  22. int PASCAL WinMain (HANDLE hThisInstance, HANDLE hPrevInstance,
  23.                     LPSTR lpszCmdParam, int nCmdShow)
  24. {
  25.     MSG         msg;
  26.     WNDCLASS    wndclass;
  27.     HWND        hwnd;
  28.     RECT        rect;
  29.  
  30.  
  31.     /* Register window classes */
  32.  
  33.     if (!hPrevInstance) {
  34.         wndclass.style          = CS_HREDRAW | CS_VREDRAW;
  35.         wndclass.lpfnWndProc    = MainWinProc;
  36.         wndclass.cbClsExtra     = 0;
  37.         wndclass.cbWndExtra     = 0;
  38.         wndclass.hInstance      = hThisInstance;
  39.         wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
  40.         wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  41.         wndclass.hbrBackground  = COLOR_APPWORKSPACE + 1;
  42.         wndclass.lpszMenuName   = NULL;
  43.         wndclass.lpszClassName  = "Frame";
  44.  
  45.         RegisterClass(&wndclass);
  46.     }
  47.  
  48.     hwnd = CreateWindow("Frame", "Toolbar Test",
  49.                         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  50.                         CW_USEDEFAULT, CW_USEDEFAULT,
  51.                         CW_USEDEFAULT, CW_USEDEFAULT,
  52.                         NULL, NULL, hThisInstance, NULL);
  53.  
  54.     ShowWindow(hwnd, nCmdShow);
  55.     UpdateWindow(hwnd);
  56.  
  57.     GetClientRect(hwnd, &rect);
  58.  
  59.     tbhwnd1 = CreateToolbar (hwnd, 0, 0, rect.right, 36, 1, 42, 7, hThisInstance, tbar1, "X_Cursor");
  60.     tbhwnd2 = CreateToolbar (hwnd, 0, 36, rect.right, 36, 1, 43, 2, hThisInstance, tbar2, "X_Cursor");
  61.     cbhwnd = CreateWindow("combobox", "Hello", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,
  62.                             8, 6, 160, 200, tbhwnd1, 127, hThisInstance, NULL);
  63.  
  64.  
  65.     while (GetMessage(&msg, NULL, 0, 0)) {
  66.         TranslateMessage(&msg);
  67.         DispatchMessage(&msg);
  68.     }
  69.  
  70.     return (msg.wParam);
  71. }
  72.  
  73.  
  74. long FAR PASCAL MainWinProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  75. {
  76.     int i, j;
  77.     char buffer[256];
  78.  
  79.     /* Takes care of menu items */
  80.  
  81.     switch (message) {
  82.  
  83.     case WM_KEYDOWN:
  84.         if (wParam == VK_F2) {
  85.             i = SendMessage(tbhwnd1, BM_GETSTATE, 0, 1L);
  86.             if (i) i = 1;
  87.             SendMessage(tbhwnd1, BM_SETSTATE, !i, 1L);
  88.             SendMessage(tbhwnd1, BM_SETSTATE, i, 2L);
  89.             EnableToolbarButton(tbhwnd1, 3, !i);
  90.             EnableToolbarButton(tbhwnd1, 4, !i);
  91.             EnableToolbarButton(tbhwnd1, 6, i);
  92.             break;
  93.         }
  94.         return (0);
  95.  
  96.     case WM_COMMAND:
  97.         sprintf(buffer, "WM_COMMAND, Toolbar:%d, Button:%d, lParam%08lx (%s)", LOBYTE(wParam), HIBYTE(wParam),
  98.                 lParam, (HIWORD(lParam) == BN_CLICKED) ? "Clicked" : "Something else");
  99.         SetWindowText(hwnd, buffer);
  100.  
  101.         j = HIBYTE(wParam);
  102.  
  103.         switch (j) {
  104.             case 1: i = SendMessage(tbhwnd1, BM_GETSTATE, 0, (LONG) j);
  105.                     if (i) break;
  106.                     SendMessage(tbhwnd1, BM_SETSTATE, TRUE, 1L);
  107.                     SendMessage(tbhwnd1, BM_SETSTATE, FALSE, 2L);
  108.                     EnableToolbarButton(tbhwnd1, 3, TRUE);
  109.                     EnableToolbarButton(tbhwnd1, 4, TRUE);
  110.                     EnableToolbarButton(tbhwnd1, 6, FALSE);
  111.                     break;
  112.             case 2: i = SendMessage(tbhwnd1, BM_GETSTATE, 0, (LONG) j);
  113.                     if (i) break;
  114.                     SendMessage(tbhwnd1, BM_SETSTATE, FALSE, 1L);
  115.                     SendMessage(tbhwnd1, BM_SETSTATE, TRUE, 2L);
  116.                     EnableToolbarButton(tbhwnd1, 3, FALSE);
  117.                     EnableToolbarButton(tbhwnd1, 4, FALSE);
  118.                     EnableToolbarButton(tbhwnd1, 6, TRUE);
  119.                     break;
  120.             case 7:
  121.             case 8:
  122.                     i = SendMessage(tbhwnd2, BM_GETSTATE, 0, (LONG) j);
  123.                     if (i) break;
  124.                     SendMessage(tbhwnd2, BM_SETSTATE, TRUE, (LONG) j);
  125.                     SendMessage(tbhwnd2, BM_SETSTATE, FALSE, (j == 7) ? 8L : 7L);
  126.                     break;
  127.         }
  128.         return (0);
  129.  
  130.     case WM_DESTROY:
  131.         PostQuitMessage(0);
  132.         return (0);
  133.     }
  134.  
  135.     return (DefWindowProc(hwnd, message, wParam, lParam));
  136. }
  137.